<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/1/13
 * Time: 13:35
 */

namespace app\api\controller;


class ServerMiddleware extends Base
{
    /**
     * @name 中间件注册
     * @author wx
     * @date 2020/1/13 13:36
     */
    public function register()
    {
        //接收参数
        $data = base64_decode(file_get_contents("php://input"));
        $data = json_decode($data,true);

        $server = new \app\api\service\ServerMiddleware();
        $res = $server->register($data);

        $this->jsonOutPut($res);
    }

    /**
     * @name 得到更新路径
     * @author wx
     * @date 2020/1/13 15:08
     */
    public function getPackagePath()
    {
        $data = base64_decode(file_get_contents("php://input"));
        $data = json_decode($data,true);

        $fileLog = '../runtime/log/ServerUpdate.log';
        if (file_exists($fileLog) && filesize($fileLog) >= 5 * 1024 * 1024 * 1024) {
            unlink($fileLog);
        }
        $params = $_SERVER['REMOTE_ADDR'].'返回中间件更新包路径:'.date('Y-m-d H:i:s',time()).PHP_EOL.json_encode($data,JSON_UNESCAPED_UNICODE).PHP_EOL;
        file_put_contents($fileLog,$params,FILE_APPEND);

        $server = new \app\api\service\ServerMiddleware();
        $list = $server->getPackagePath($data);

        $this->jsonOutPut($list);
    }
}